package org.evil.dog.gateway.enums;

import java.util.HashMap;
import java.util.Map;

public enum ErrorEnum {
    //业务错误
    BUSINESS_ERR(601, "未定义错误"),
    //参数错误
    PARAM_ERR(602, "参数错误"),
    //服务之间调用问题
    NET_ERR(603, "网络错误"),
    AUTH_ERR(604, "无效用户"),
    TOKEN_ERR(604,"用户鉴权错误"),
    TOKEN_EXP(605,"用户信息过期"),
    HEAD_PARAM_ERR(606,"无法获取APP版本信息"),
    GATEWAY_ERR(607,"网关错误"),;


    private int code;
    private String info;

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    ErrorEnum(int code, String info) {
        this.code = code;
        this.info = info;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Map<String,Object> getMsg() {
        Map<String,Object> map=new HashMap<>();
        map.put("msg",info);
        return map;
    }

    public static ErrorEnum getErrorEnum(int code) {
        ErrorEnum[] errorEnums = ErrorEnum.values();
        for (ErrorEnum errorEnum : errorEnums) {
            if (code == errorEnum.getCode()) {
                return errorEnum;
            }
        }
        return BUSINESS_ERR;
    }
}
